package com.locationpath.android.setting;

import com.locationpath.android.GlobalVariables;
import com.locationpath.android.schedule.SchedulerUtils;

import android.content.Context;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;

public class ScheduleCheckBoxPreference extends CheckBoxPreference {

	public ScheduleCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public ScheduleCheckBoxPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ScheduleCheckBoxPreference(Context context) {
		super(context);
	}

	@Override
	protected void onClick() {
		super.onClick();

		if (GlobalVariables.IS_RUNNING_SCHEDULE) {

			SchedulerUtils.stopScheduleService(getContext().getApplicationContext());

			Handler handler = new Handler();
			handler.postDelayed(new Runnable() {
				
				@Override
				public void run() {
					SchedulerUtils.startScheduleService(getContext().getApplicationContext());
					
				}
			}, 1 * 1000);

		}
	}

	
}
